<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>审核表单</title>
<link rel="stylesheet" href="/res/layui/css/layui.css" media="all">
</head>
<body>
<script src="/res/layui/layui.js"></script>
	<script src="/res/js/jquery-3.4.1.min.js"></script>
<script src="/res/js/util.js"></script>
<!-- 这里是弹出层的表单信息 -->
<div class="layui-row" id="popUpdateTest">
	<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
		<legend>审核信息填写</legend>
	</fieldset>
	<form class="layui-form" id="shForm" action="/ZgsSellOrder/SellSh.action" method="post">
		<!-- 采购 原材料订单 id -->
		<input type="hidden" name="purchaseId" id="purchaseId">
		<!-- 药品订单 id-->
		<input type="hidden" name="drugId" id="drugId">
		<!-- 生产订单 id-->
		<input type="hidden" name="planId" id="planId">
		<!-- 批发订单 id-->
		<input type="hidden" name="sellId" id="sellId">
		<div class="layui-form-item">
			<label class="layui-form-label">职位</label>
			<div class="layui-input-block">
				<input type="hidden" name="qwId" id="pwId">
				<input type="hidden" name="auditSection" id="auditSection">
				<input type="text" maxlength="20"  autocomplete="off" class="layui-input layui-disabled" disabled style="width:280px;" id="position">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">订单名称</label>
			<div class="layui-input-block">
				<input type="text" name="roleCode" id="roleCode" maxlength="20" value="分店采购订单"  autocomplete="off" class="layui-input layui-disabled" disabled style="width:280px;">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">是否通过</label>
			<div class="layui-input-inline">
				<select lay-verify="required" lay-filter="isva" name="isva" lay-search="" id="auditPass">
					<option value="">是否通过</option>
				</select>
			</div>
		</div>
		<div class="layui-form-item layui-form-text" id="auditCause">
			<label class="layui-form-label">审核意见</label>
			<div class="layui-input-block">
				<textarea placeholder="请输入内容" id="reviewRemark" maxlength="20" name="reviewRemark" class="layui-textarea" lay-verify="required" required></textarea>
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-input-block">
				<input type="button" lay-submit="" class="layui-btn" lay-filter="auditAdd" value="提交" id="tj">
			</div>
		</div>
	</form>
</div>
		 <script>

layui.use(['form','laydate', 'laypage', 'layer', 'table', 'upload', 'element','tree'], function(){
  var form = layui.form
  ,laydate = layui.laydate //日期
  ,laypage = layui.laypage //分页
  ,layer = layui.layer //弹层
  ,table = layui.table //表格
  ,upload = layui.upload //上传
  ,element = layui.element; //元素操作
  //日期
  laydate.render({
	    elem: '#date'
  });
  laydate.render({
	    elem: '#date1'
  });
  var $ = layui.$;
  //获取所点击审核的人的权限
  var status = getQueryString("status");
	//动态添加（是否通过）
	$("#auditPass").append(`<option value="${status}">是</option>
                    <option value="${(status - 0) + 1}">否</option>`);
	form.render();
  //被审核的id
  var id = getQueryString("id");
  //将采购单（原材料单）id赋值
  $("#purchaseId").val(id);
	//将药品单id赋值
	$("#drugId").val(id);
	//将生产id赋值
	$("#planId").val(id);
	//将销售id赋值
	$("#sellId").val(id);

   if(status == "30"){
	  $("#position").val("分公司采购经理");
  }else if(status == "40"){
	  $("#position").val("分公司总经理");
  }else if(status == "50"){
	  $("#position").val("总公司销售经理");
  }else if(status == "60"){
	  $("#position").val("总店总经理");
  }else if(status == "66"){
	   $("#position").val("总店总经理");
   }else if(status == "70"){
	   $("#position").val("总公司财务");
   }else if(status == "80"){
   	  $("#position").val("分公司财务");
   }
  //监听Tab切换
  element.on('tab(demo)', function(data){
    layer.msg('切换了：'+ this.innerHTML);
    console.log(data);
  });

	let url = null;
	var audit = getQueryString("audit");
	//获取当前是什么审核
	if(audit=='rawMaterial'){
		url = "/auditRecord/updateRawMaterialIsva";
		$("#roleCode").val('总店原材料订单');
	}else if(audit=='drug'){
		url = "/auditRecord/updateDrugIsva";
		$("#roleCode").val('总店药品订单');
	}else if(audit=='production'){
		url = "/auditRecord/updateProductionIsva";
		$("#roleCode").val('总店生产订单');
	}else if(audit=='salesReturn'){
		url = "/auditRecord/updateFinanceIsvaReturn";
		$("#roleCode").val('分店退货订单');
	}else if(audit=='salesReturnFinance'){//分公司退货审核
		url = "/auditRecord/updateFinanceIsvaReturn";
		$("#roleCode").val('分店退货订单财务');
	}else if(audit=='FGSfinance'){
		url = "/auditRecord/updateFinanceIsva";
		$("#roleCode").val('分店采购订单');
	}else if(audit=='wholesaleAudit'){
		url = "/auditRecord/updateWholesaleAudit";
		$("#roleCode").val('分店批发订单');
	}else{
		url = "/auditRecord/updatePurchaseIsva";
		$("#roleCode").val('分店采购订单');
	}

	let num = 0;

	//审核提交
	form.on("submit(auditAdd)", function (data) {
		num++;
		//只能点击一次
		if(num==1) {
			console.info(data);
			$.ajax({
				async: false, //同步
				url: url,
				type: 'POST',
				data: data.field,
				dataType: 'json',
				success: function (obj) {
					if (obj.status == 20) {
						parent.closeOpen(obj.message);
					} else {
						parent.errorCloseOpen(obj.message);

					}
				},
				error: function () {

				}
			});
		}
		return false;
	});

  form.on("select(isva)",function(data){
		var qwId = $("#pwId").val();
		if(data.value == "1"){
			var url = "Repertory/findByFilIdAndPwId.action";
			var data = {"qwId":qwId};
			$.ajax({
				url:url,
				data:data,
				success:function(msg){
					if(msg == "1"){
						layer.msg("您提交的订单中,有一种药品或多种药品总店的库存不足",{time:1500})
					}else if(msg == "2"){
						layer.msg("您提交的订单中,有一种药品或多种药品总店的库存不存在",{time:1500});
					}else if(msg == "3"){
						layer.msg("您提交的订单中,没有明细数据",{time:1500});
					}else if(msg == "no"){
						layer.msg("库存不存在",{time:1500});
					}else if(msg == "ok"){
						$("#tj").attr("type","submit");
						$("#tj").attr("lay-submit","");
					}
					
				}
			});
			
		}else {
			$("#tj").attr("type","submit");
			$("#tj").attr("lay-submit","");
		}
	  
  });
  
	});

/**
 得到地址栏的参数
 */
function getQueryString(name) {
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
	var r = window.location.search.substr(1).match(reg);
	if (r != null) return unescape(r[2]);
	return null;
}
</script>
</body>
</html>